<template>
  <div class="logistics_statistics">
    <div class="statistics_choose">
      <div class="statistics_choose_time" @click="onShowPicker()" v-if="['3', '4'].includes(this.userType)">
        <p class="item-text">{{ orgName }}</p>
        <span></span>
      </div>
      <div class="statistics_choose_time" @click="timeChooseYear(chooseYear)">
        {{ chooseYear || '年份' }}
        <span></span>
      </div>
      <div class="statistics_choose_time" @click="timeChooseMonth(chooseMonth)">
        {{ chooseMonth || '月份' }}
        <span></span>
      </div>
    </div>
    <div class="statistics_con">
      <div class="con_title">{{ monthData }}月办公用品领用明细汇总</div>
      <div class="con_box">
        <div class="box_th">
          <van-row gutter="5">
            <van-col span="10">物品名称</van-col>
            <van-col span="6">规格</van-col>
            <van-col span="4">申请数量</van-col>
            <van-col span="4">实际数量</van-col>
          </van-row>
        </div>
        <div class="box_td">
          <van-row gutter="5" v-for="item in tableData" :key="item.typeId">
            <van-col span="10">{{ item.name }}</van-col>
            <van-col span="6">{{ item.specs }}</van-col>
            <van-col span="4">{{ item.applyNumber }}</van-col>
            <van-col span="4">{{ item.realityNumber }}</van-col>
          </van-row>
        </div>
      </div>
    </div>
    <van-popup v-model="showTimeYear" position="bottom">
      <van-picker
        title="选择年份"
        show-toolbar
        :columns="yearOption"
        @confirm="timeConfirmYear"
        @cancel="showTimeYear = false"></van-picker>
    </van-popup>
    <van-popup v-model="showTimeMonth" position="bottom">
      <van-picker
        title="选择年份"
        show-toolbar
        :columns="monthOption"
        @confirm="timeConfirmMonth"
        @cancel="showTimeMonth = false"></van-picker>
    </van-popup>
    <van-popup v-model="showTaskDept" position="bottom" get-container="#app">
      <van-picker
        show-toolbar
        value-key="name"
        title="选择窗口"
        :columns="dataList"
        @confirm="onDeptConfirm"
        @cancel="showTaskDept = false" />
    </van-popup>
  </div>
</template>

<script>
import { getStatisticsList, getWindowList } from '@api/api-dailyManage.js'
import moment from 'moment'
export default {
  name: 'logisticsStatistics',
  components: {},
  props: {
    userType: {
      type: String,
      default: '1',
    },
  },
  data() {
    return {
      yearOption: [{ text: '2022年', value: '2022' }],
      yearData: '2022',
      monthOption: [
        { text: '7月', value: '7' },
        { text: '8月', value: '8' },
        { text: '9月', value: '9' },
        { text: '10月', value: '10' },
        { text: '11月', value: '11' },
        { text: '12月', value: '12' },
      ],
      monthData: moment().format('M'),
      showTimeYear: false,
      showTimeMonth: false,
      chooseYear: '2022年',
      chooseMonth: '7月',
      tableData: [],
      userInfo: JSON.parse(localStorage.userInfo),
      showTaskDept: false,
      orgId: '',
      orgName: '',
      dataList: [],
    }
  },
  created() {},
  mounted() {
    if (['1', '2', '5'].includes(this.userType)) {
      this.orgId = this.userInfo.loginPostInfo.orgId
      this.getData()
    } else {
      this.getWindowList()
    }
  },
  methods: {
    // 选择时间
    timeChooseYear(time) {
      this.showTimeYear = true
    },
    timeChooseMonth(time) {
      this.showTimeMonth = true
    },
    // 时间确定
    timeConfirmYear(val) {
      this.showTimeYear = false
      this.chooseYear = val.text
      this.yearData = val.value
      this.resizeList()
    },
    timeConfirmMonth(val) {
      this.showTimeMonth = false
      this.chooseMonth = val.text
      this.monthData = val.value
      this.resizeList()
    },
    resizeList() {
      this.listDate = []
      this.getData()
    },
    getData() {
      getStatisticsList({
        month: this.monthData,
        orgId: this.orgId,
        year: this.yearData,
      }).then(res => {
        this.tableData = res.data
      })
    },
    onShowPicker() {
      this.showTaskDept = true
    },
    onDeptConfirm(value, index) {
      this.orgName = value.name
      this.orgId = value.id
      this.showTaskDept = false
      this.resizeList()
    },
    getWindowList() {
      getWindowList().then(res => {
        if (res.code === 0) {
          const obj = {
            id: '',
            name: '全部窗口',
          }
          this.dataList = [obj, ...res.data]
          this.orgName = obj.name
          this.orgId = obj.id
          this.getData()
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.logistics_statistics {
  font-size: 12px;
  /deep/.van-tab__text {
    line-height: 30px;
    font-size: 13px;
  }
  /deep/ .van-popup {
    position: absolute;
  }
  /deep/ .van-overlay {
    position: absolute;
  }

  .statistics_choose {
    display: flex;
    align-items: center;
    // justify-content: space-between;
    height: 36px;
    background-color: #f4f6f8;
    position: relative;
    padding: 0 10px;
    .statistics_choose_time {
      display: flex;
      align-items: center;
      margin-left: 5px;
      margin-right: 10px;
      span {
        width: 0;
        height: 0;
        border-top: 4px solid #dcdee0;
        border-left: 4px solid transparent;
        border-right: 4px solid transparent;
        margin-left: 5px;
      }
    }
  }
  .statistics_con {
    padding: 7px 10px;
    font-size: 13px;
    color: #333333;
    text-align: center;
    .con_title {
      font-size: 15px;
      font-weight: 600;
      margin: 5px 0 10px;
      border-bottom: 1px solid #dcdee0;
      padding-bottom: 10px;
    }
    .con_box {
      .box_th {
        margin: 10px 0;
        border-bottom: 1px solid #dcdee0;
        padding-bottom: 10px;
      }
      .box_td {
        .van-row {
          margin: 10px 0;
        }
      }
    }
  }
}
</style>
